import instance from "./index"
//获取全部数据
export function getTodo(){
  return instance({
    method:"GET",
    url:"/List",
  })
}
//添加内容
export function addTodo(obj){
  return instance({
    method:"POST",
    url:"/List",
    data:obj
  })
}
//删除
export function delTodo(id){
  return instance({
    method:"DELETE",
    url:`/List/${id}`,
  })
}
//修改数据
export function WriteTodo(id,obj){
  return instance({
    method:"PATCH",
    url:`/List/${id}`,
    data:obj
  })
}
//根据ID获取单个数据
export function getItem(id){
  return instance({
    method:"GET",
    url:`/List/${id}`,
  })
}

//模糊查询
export function getList(obj){
  //转为key=value的格式
  console.log("传递到接口中的对象", obj)
  //方法一
  // let url = ''
  // for(let k in obj){
  //   url+= k + "=" +obj[k]
  // }
  // console.log("转换为字符串后",url);
  //方法二
  const  searchURL = new URLSearchParams(obj).toString()
  // console.log("方法一",searchURL);
  console.log("方法二",decodeURI(searchURL))
  return instance({
    method:"GET",
    url:`/List?${searchURL}`
  })
}